//
//  SpecialThirdViewController.m
//  味·道
//
//  Created by lizi on 15/7/1.
//  Copyright (c) 2015年 WMR. All rights reserved.
//

#import "SpecialThirdViewController.h"
#import "MaocHeader.h"


@interface SpecialThirdViewController ()
@property (nonatomic,retain)UIWebView *webView;
@property (nonatomic,retain)UIActivityIndicatorView *activityIndicatorView;
@end

@implementation SpecialThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.2 blue:0.5 alpha:1];
    [self createWebView];
    [self createCustomLab];
    [self createBackBtn];
    [self createShareBtn];
    // Do any additional setup after loading the view.
}
- (void)createWebView{
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 55, SCREEN_WIDTH, SCREEN_HEIGHT-55)];
    _webView.scrollView.backgroundColor = [UIColor whiteColor];
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ibaby.ipadown.com/api/food/food.show.detail.php?id=%@",self.Id]]]];
    _webView.delegate = self;
    [self.view addSubview:_webView];
}
- (void)createCustomLab{
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(150, 20, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"详细做法"];
    customLab.font = [UIFont boldSystemFontOfSize:18];
    [self.view addSubview:customLab];
    [customLab release];
}
- (void)createBackBtn{
    UIButton *back = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [back setTitle:@"返回" forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backFor:) forControlEvents:UIControlEventTouchUpInside];
    back.frame = CGRectMake(10, 10, 50, 50);
    [self.view addSubview:back];
}
- (void)backFor:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)createShareBtn{
    UIButton *share = [UIButton buttonWithType:(UIButtonTypeSystem)];
//    share.backgroundColor = [UIColor greenColor];
    [share setBackgroundImage:[UIImage imageNamed:@"share"] forState:(UIControlStateNormal)];
    [share addTarget:self action:@selector(WL_CreateShare:) forControlEvents:UIControlEventTouchUpInside];
    share.frame = CGRectMake(330, 20, 30, 30);
    [self.view addSubview:share];
}
- (void)WL_CreateShare:(id)button{
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"559202ac67e58ed15c00167e" shareText:@"分享" shareImage:[UIImage imageNamed:@""] shareToSnsNames:[NSArray arrayWithObjects:UMShareToDouban,UMShareToSina,UMShareToTwitter,nil] delegate:self];
}
#warning  webView
-(void)webViewDidStartLoad:(UIWebView *)webView{
    CGFloat height = self.view.frame.size.height;
    //创建UIActivityIndicatorView背底半透明View
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
    [view setTag:108];//设置tag值
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.5];
    [self.webView addSubview:view];
    
    _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [_activityIndicatorView setCenter:view.center];
    [_activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [view addSubview:_activityIndicatorView];
    [_activityIndicatorView startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [_activityIndicatorView stopAnimating];
    UIView *view = [self.webView viewWithTag:108];
    [view removeFromSuperview];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [_activityIndicatorView stopAnimating];
    UIView *view = [self.webView viewWithTag:108];
    [view removeFromSuperview];
    NSLog(@"error:%@",error);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
